/**
 * Created by Wilson on 1/23/2015.
 */
(function () {
    angular.module('app')
        .controller('modelSelectorController', modelSelectorController);

    modelSelectorController.$inject = ['$scope', 'tunnelService', 'carService', 'alertController'];
    function modelSelectorController($scope, tunnelService, carService, alertController) {

        $scope.confirmModel = confirmModel;

        $scope.getModelList = getModelList;

        function confirmModel(carId) {
            carService.confirmModel(carId).then(function (data) {
                alertController.simpleAlert(data.errMsg);
            }).catch(function (data) {
                alertController.simpleAlert(data.errMsg);
            });
        }

        function getModelList() {
            var typeId = tunnelService.getData('seriesSelector.typeId');
            var nameId = tunnelService.getData('seriesSelector.nameId');
            carService.getModelList(typeId, nameId).then(function (data) {
                $scope.modelList = data.datas;
            }).catch(function (data) {
                alertController.simpleAlert(data.errMsg);
            });
        }

    }

})();